<?php
namespace app\index\controller;
use service\services\AlgoLogService;
use service\services\TopicService;
use service\services\UserService;
use think\Request;
/**
 * Description of Student
 *
 * @author zhangqiquan
 */
class AlgoLog extends Base{

    public function request()
    {
        $request=Request::instance();

        $topicId=$request->param("topicId");
        $username=$request->param("username");
        $module_type=$request->param("module_type");
        $requestApi=$request->param("requestApi");

        $userService=new UserService();
        $user_id=$userService->getUid($username);
        $algoLogService=new AlgoLogService();

        $map=[];
        if($topicId>-1)
        {
            $map["topicId"]=$topicId;
        }

            if($module_type>-1)
            {
                $map["module_type"]=$module_type;
            }
        if($username) {
            $map["user_id"] = $user_id;
        }

        if($requestApi!="-1"&&!empty($requestApi))
        {
            $map["request_api"] = $requestApi;
        }
        $pageSize=config('list_rows');
        $param=$request->param();
        $result=$algoLogService->getRequestLogList($map,$pageSize,$param,false);
        $topicService=new TopicService();
        $topicList=$topicService->getTopicList();
        $moduleTypeList=$this->getModuleTypeList();
        $requestApiList=$algoLogService->getRequestApiList();
        $this->assign("requestApiList",$requestApiList);
        $this->assign("requestApi",$requestApi);
        $this->assign("topicList",$topicList);
        $this->assign("topicId",$topicId);
        $this->assign("module_type",$module_type);
        $this->assign("username",$username);
        $this->assign("moduleTypeList",$moduleTypeList);
        $this->assign("data",$result["data"]);
        $this->assign("page",$result["page"]);
        return $this->fetch("alogLog/index");
    }

    private  function getModuleTypeList()
    {
       /* $data=[
            1=>[1=>"巩固提高"],
            2=>[1=>"高效学习",2=>"学习检测"],
            3=>[1=>"竞赛拓展"]
        ]*/
        $data=[
            ["id"=>1,"name"=>"巩固提高"],
            ["id"=>2,"name"=>"边学边练"],
            ["id"=>3,"name"=>"竞赛拓展"]
        ];
        return $data;
    }

    public function tagCode()
    {
        $request=Request::instance();
        $topicId=$request->param("topicId");
        $username=$request->param("username");
        $module_type=$request->param("module_type");
        $userService=new UserService();
        $user_id=$userService->getUid($username);
        $algoLogService=new AlgoLogService();
        $map=[];
        if($topicId>-1)
        {
            $map["topicId"]=$topicId;
        }

        if($module_type>-1)
        {
            $map["module_type"]=$module_type;
        }
        if($username) {
            $map["user_id"] = $user_id;
        }
        $pageSize=config('list_rows');
        $param=$request->param();
        $result=$algoLogService->getTagCodeLogList($map,$pageSize,$param,false);
        $topicService=new TopicService();
        $topicList=$topicService->getTopicList();
        $moduleTypeList=$this->getModuleTypeList();
        $this->assign("topicList",$topicList);
        $this->assign("topicId",$topicId);
        $this->assign("module_type",$module_type);
        $this->assign("username",$username);
        $this->assign("moduleTypeList",$moduleTypeList);
        $this->assign("data",$result["data"]);
        $this->assign("page",$result["page"]);
        return $this->fetch("alogLog/tagCode");

    }


}
